<?php
define('ROOT_PATH','../');
define('TEMPLATE_DIR','gmer/');
$_GET['game_id']=0;
$_GET['server_id']=0;
setcookie('game_id',$_GET['game_id'],0,'/');
setcookie('server_id',$_GET['server_id'],0,'/');
require_once(ROOT_PATH.'code/bean/config.inc.php');
require_once(ROOT_PATH.'code/class/gmer/class.admin_user.php');
require_once(ROOT_PATH.'code/class/gmer/class.admin_ques_list.php');
require_once(ROOT_PATH.'code/bean/smarty.config.inc.php');
require_once(ROOT_PATH.'code/bean/db_config.inc.php');
if(isset($_POST['username'])) {
	$user=$_POST['username'];
	$pass=$_POST['password'];
	$sql="select * from gm_user where gm_name='$user' and pass='$pass'";
	$res=sql_get_one($sql,__LINE__);
	if(!$res) js_alert('认证失败,重新登录',true);
	else {
		setcookie('tovy_login',1,null,'/');
		setcookie('user_name',$res['gm_name'],null,'/');
		setcookie('nick_name',$res['gm_name'],null,'/');
		if($pass=='123456') js_alert('请修改初始密码',true,'edit_pass.php');
		else header('location:'.get_self());
	}
}

$url=$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
setcookie('cs_return_url',$url,time()+360000,'/');

$user=new gmer_user();

$session=check_login('admin/index.php');
if($user->session) {
	
	if(isset($_GET['set_game_id'])) {
		setcookie('set_game_id',$_GET['set_game_id'],time()+10*24*3600,'/');
	}

	$game_id=-1;	
	if(isset($_GET['set_game_id'])) {
		if($_GET['set_game_id']!='-1') {
			$game_id=$_GET['set_game_id'];
		}
	}else {
		if(isset($_COOKIE['set_game_id'])) {
			if($_COOKIE['set_game_id']!=-1) {
				$game_id=$_COOKIE['set_game_id'];
			}
		}
	}

	$ques_list=new ques_list();
	$ques_list->get_list();
	$tpl->assign('user',$user);	
	$tpl->assign('game_id',$game_id);	
	$tpl->assign('ques_list',$ques_list);
	$tpl->assign('file_gm_info','tpl/gm_user_info.tpl');
	$tpl->display('gm_logined.html');
}else {
	$tpl->display('gm_login.html');
}
?>